import { createStore } from "vuex";

// 创建一个新的 store 实例
export default createStore({
    state: {
        tabs:[],//面包屑导航
        menus:[
            // 配置一级菜单和二级菜单
            {
                menusIndex:"1",
                title:'员工管理',
                icon:'user',
                children:[
                    {
                        title:'基本资料管理',
                        path:'/empManagement/basicInfoManagement'
                    }
                ]
            },
            {
                menusIndex:"2",
                title:'人事管理',
                icon:'Files',
                children:[
                    {
                        title:'员工调动',
                        path:'/hrManagement/empTransfer'
                    }
                ]
            },
            {
                menusIndex:"3",
                title:'系统管理',
                icon:'setting',
                children:[
                    {
                        title:'部门管理',
                        path:'/systemManagement/departmentManagement'
                    },
                    {
                        title:'职位管理',
                        path:'/systemManagement/positionManagement'
                    }
                ]
            },
            {
                menusIndex:"4",
                title:'流程管理',
                icon:'Paperclip',
                children:[
                    {
                        title:'审批管理',
                        path:'/processManagement/approvalManagement',
                    }
                ]
            },
            {
                menusIndex:"5",
                title:'公告管理',
                icon:'Document',
                children:[
                    {
                        title:'管理公告',
                        path:'/noticeManagement/manageNotice',
                    }
                ]
            }
        ]
    },
    getters: {
        /**
         * 获取所有的tab
         * @param state
         * @returns
         */
        tabs(state) {
            return state.tabs;
        },

        /**
         * 获取所有的菜单
         * @param state
         * @returns
         */
        menus(state) {
            return state.menus;
        }
    },
    mutations: {
        //添加菜单
        addMenus(state, param) {
            state.menus = param
        },
        //删除菜单
        deleteTabByIndex(state, index) {
            state.tabs.splice(index, 1);
        },
        /**
         * 清空tab
         */
        clearTab(state, param) {
            state.tabs = param
        },
        /**
       * 向vuex中添加tab内容
       * @param state
       * @param payload
       */
        addTab(state, payload) {
            let path = payload.path;
            if (path) {
                let result = state.tabs.filter((item) => {
                    return item.path == path;
                });
                //判断是否存在,如果不存在才需要加入到state的tabs中
                if (result.length == 0) {
                    if (state.tabs.length == 10) {
                        //删除第二个
                        state.tabs.splice(1, 1)
                    }
                    //需要添加
                    state.tabs.push(payload);
                }

            }
        },
    },
    actions: {

    },
    modules: {

    }
})